package com.jsyh.maidu.adapter.home;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;

import com.jsyh.maidu.R;
import com.jsyh.maidu.activity.GoodsFilterActivity;
import com.jsyh.maidu.config.ConfigValue;
import com.jsyh.maidu.model.Brands;
import com.squareup.picasso.Picasso;

import java.util.List;


/**
 * Created by Administrator on 2017/6/8.
 */

public class GvBrandAdapter extends BaseAdapter {
    private Context context;
    private LayoutInflater inflater;
    private List<Brands> datas;


    public GvBrandAdapter(Context context, List<Brands> partDatas) {
        this.context = context;
        inflater = LayoutInflater.from(context);
        this.datas = partDatas;
    }

    @Override
    public int getCount() {
        return datas.size();
    }

    @Override
    public Object getItem(int i) {
        return datas.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(final int i, View view, ViewGroup viewGroup) {
        ViewHolder holder = null;
        if (view == null) {
            view = inflater.inflate(R.layout.gv_item_brand, null);
            holder = new ViewHolder();
            holder.imageView = (ImageView) view.findViewById(R.id.imageview);
            view.setTag(holder);
        } else {
            holder = (ViewHolder) view.getTag();
        }

        Picasso.with(context).load(ConfigValue.IMG_IP + datas.get(i).getBrand_logo()).into(holder.imageView);
        view.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(context, GoodsFilterActivity.class);
                Bundle bundle = new Bundle();
                bundle.putInt("brand_id", Integer.valueOf(datas.get(i).getBrand_id()));
                bundle.putBoolean("home_brand", true);
                intent.putExtras(bundle);
                context.startActivity(intent);
            }
        });

        return view;
    }

    class ViewHolder {
        private ImageView imageView;
    }
}
